//
//  PageContrlTestVC.swift
//  elarc01
//
//  Created by elarc on 16/8/12.
//  Copyright © 2016年 elarc. All rights reserved.
//

import UIKit

class PageContrlTestVC: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        configScrollView()
    }
    
    var snakePageControl: SnakePageControl!
    var filledPageControl: FilledPageControl!
    var pillPageControl: PillPageControl!
    var scrollingPageControl: ScrollingPageControl!
    var scrollView: UIScrollView!
    
    
    func configScrollView() -> Void {
        
        snakePageControl = SnakePageControl()
        snakePageControl.frame = CGRectMake(0, 200, self.view.frame.size.width, 20)
        snakePageControl.pageCount = 3
        
        filledPageControl = FilledPageControl()
        filledPageControl.frame = CGRectMake(0, 250, self.view.frame.size.width, 20)
        filledPageControl.pageCount = 3
        
        pillPageControl = PillPageControl()
        pillPageControl.frame = CGRectMake(0, 300, self.view.frame.size.width, 20)
        pillPageControl.pageCount = 3
        
        scrollingPageControl = ScrollingPageControl()
        scrollingPageControl.frame = CGRectMake(0, 350, self.view.frame.size.width, 20)
        scrollingPageControl.pageCount = 3
        
        view.addSubview(snakePageControl)
        view.addSubview(filledPageControl)
        view.addSubview(pillPageControl)
        view.addSubview(scrollingPageControl)
        
        view.backgroundColor = UIColor.blackColor()
        scrollView = UIScrollView()
        scrollView .frame = UIScreen.mainScreen().bounds
        view.addSubview(scrollView)
        
        
        scrollView.delegate = self
        scrollView.pagingEnabled = true
        let contentSize = CGSize(width: scrollView.bounds.width * 3,
                                 height: scrollView.bounds.height)
        scrollView.contentSize = contentSize
    }
}
extension PageContrlTestVC: UIScrollViewDelegate {
    func scrollViewDidScroll(scrollView: UIScrollView) {
        let page = scrollView.contentOffset.x / scrollView.bounds.width
        let progressInPage = scrollView.contentOffset.x - (page * scrollView.bounds.width)
        let progress = CGFloat(page) + progressInPage
        snakePageControl.progress = progress
        filledPageControl.progress = progress
        pillPageControl.progress = progress
        scrollingPageControl.progress = progress
    }
}

